#pragma once

#include "RBTree.h"

namespace byh
{
	template<class K>
	class set
	{
	public:
		struct KeyOfSet
		{
			const K& operator()(const K& key)
			{
				return key;
			}
		};

		typedef typename RBTree<K, const K, KeyOfSet>::iterator iterator;
		typedef typename RBTree<K,const K, KeyOfSet>::const_iterator const_iterator;

		pair<iterator, bool> insert(const K& key)
		{
			return _t.insert(key);
		}

		iterator begin()
		{
			return _t.begin();
		}

		iterator end()
		{
			return _t.end();
		}

		const_iterator begin() const
		{
			return _t.begin();
		}

		const_iterator end() const
		{
			return _t.end();
		}

	//protected:
		RBTree<K, const K, KeyOfSet> _t;
	};

	void Print(const set<int>& s)
	{
		set<int>::iterator it = s.begin();
		while (it != s.end())
		{
			//*it += 3;
			cout << *it << " ";
			++it;
		}
		cout << endl;
	}

	void Test_set()
	{
		set<int> s;
		s.insert(2);
		s.insert(6);
		s.insert(8);
		s.insert(2);
		s.insert(1);

		//set<int>::iterator it = s.begin();
		//while (it != s.end())
		//{
		//	//*it += 5;
		//	cout << *it << " ";
		//	++it;
		//}
		//cout << endl;

		Print(s);
	}

	void Test_set2()
	{
		set<int> s1;
		s1.insert(2);
		s1.insert(6);
		s1.insert(8);
		s1.insert(2);
		s1.insert(1);

		//set<int> copy(s);
		//Print(copy);
		set<int> s2;
		s2 = s1;
		Print(s2);
	}
}